package com.pn.controller;

import com.pn.entity.CurrentUser;
import com.pn.entity.InStore;
import com.pn.entity.Result;
import com.pn.entity.Store;
import com.pn.page.Page;
import com.pn.service.InStoreService;
import com.pn.service.StoreService;
import com.pn.utils.TokenUtils;
import com.pn.utils.WarehouseConstants;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/instore")
public class InStoreController {
    @Resource
    private StoreService storeService;
    @Resource
    private InStoreService inStoreService;
    @Resource
    private TokenUtils tokenUtils;


    @RequestMapping("/store-list")
    public Result findStoreList(){
        List<Store> allStore = storeService.findAllStore();
        return Result.ok(allStore);
    }

    //分页查询入库单数据
    @RequestMapping("/instore-page-list")
    public Result findInStoreByPage(InStore inStore, Page page){
        Page inStoreByPage = inStoreService.findInStoreByPage(inStore, page);
        return Result.ok(inStoreByPage);
    }

    //确认入库
    @RequestMapping("/instore-confirm")
    public Result confirmIsIn(@RequestBody InStore inStore, @RequestHeader(value = WarehouseConstants.HEADER_TOKEN_NAME)String token){
        CurrentUser currentUser = tokenUtils.getCurrentUser(token);
        int userId = currentUser.getUserId();
        Result result = inStoreService.modifyIsIn(inStore.getInsId(), inStore.getInNum(), inStore.getProductId(),userId);
        return result;
    }



}
